﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Office.Tools;
using Office = Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using ThreeByte.ActiveDeck.AddIn.Config.Properties;
using System.ComponentModel;
using ThreeByte.ActiveDeck.Config;
using ThreeByte.ActiveDeck.AddIn.Content.Controls;
using ThreeByte.ActiveDeck.Controls;

namespace ThreeByte.ActiveDeck.AddIn.Controls
{
    /// <summary>
    /// Interaction logic for PropertiesControl.xaml
    /// </summary>
    public partial class PropertiesControl : UserControl
    {
        public PropertiesControl() {
            InitializeComponent();
        }

        public CustomTaskPane TaskPane {
            get;
            set;
        }

        public void Show() {
            TaskPane.Visible = true;
        }

        public void Hide() {
            TaskPane.Visible = false;
        }

        public void Show(PowerPoint.Shape shape) {

            TypeText.Text = GetTypeName(shape.Type);
            //Show the shape tags

            //ShapePropertiesBinder binder = new ShapePropertiesBinder(shape);

            //PropertyDescriptorCollection propColl = TypeDescriptor.GetProperties(binder, new Attribute[] {new ActiveDeckProperty()});
            //List<PropertyBinder> propsToDisplay = new List<PropertyBinder>();
            //foreach(PropertyDescriptor desc in propColl) {
            //    propsToDisplay.Add(new PropertyBinder(binder, desc));
            //}
            //PropertyItemsControl.ItemsSource = propsToDisplay;
            
            FormGrid.SelectedObject = new PropertyTagBinder(shape);
            
            //Show();
        }


        private string GetTypeName(Office.MsoShapeType shapeType) {

            switch(shapeType) {
                case Microsoft.Office.Core.MsoShapeType.msoAutoShape:
                    return "PowerPoint AutoShape";
                case Microsoft.Office.Core.MsoShapeType.msoCallout:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoCanvas:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoChart:
                    return "PowerPoint Chart";
                case Microsoft.Office.Core.MsoShapeType.msoComment:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoDiagram:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoEmbeddedOLEObject:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoFormControl:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoFreeform:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoGroup:
                    return "PowerPoint Group";
                case Microsoft.Office.Core.MsoShapeType.msoInk:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoInkComment:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoLine:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoLinkedOLEObject:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoLinkedPicture:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoMedia:
                    return "PowerPoint Media";
                case Microsoft.Office.Core.MsoShapeType.msoOLEControlObject:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoPicture:
                    return "PowerPoint Picture";
                case Microsoft.Office.Core.MsoShapeType.msoPlaceholder:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoScriptAnchor:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoShapeTypeMixed:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoSlicer:
                    break;
                case Microsoft.Office.Core.MsoShapeType.msoSmartArt:
                    return "PowerPoint SmartArt";
                case Microsoft.Office.Core.MsoShapeType.msoTable:
                    return "PowerPoint Table";
                case Microsoft.Office.Core.MsoShapeType.msoTextBox:
                    return "PowerPoint TextBox";
                case Microsoft.Office.Core.MsoShapeType.msoTextEffect:
                    return "PowerPoint TextEffect";
                default:
                    break;
            }
            return "PowerPoint Shape";
        }

        //internal void Show(DesignerControl control) {
        //    TypeText.Text = control.GetType().ToString();



        //}

        internal void Show(object obj) {
            TypeText.Text = obj.GetType().Name;

            //Filter the objects we want to show
            if(obj is DesignerControl
                || obj is PowerPoint.Shape) {
                FormGrid.SelectedObject = obj;

                //Show();
            }


            //List<object> propsToDisplay = new List<object>();
            //propsToDisplay.Add(new ActionBinder(button));

            ////If there is already an Action Configured, show the details
            //if(button.Action != null) {
            //    propsToDisplay.Add(new MockPropertyBinder("Action", button.Action.ToString()));
            //}
            //PropertyItemsControl.ItemsSource = propsToDisplay;
            
        }

        internal void Show(DesignerVideo video) {
            TypeText.Text = "DesignerVideo";

            //List<object> propsToDisplay = new List<object>();
            //propsToDisplay.Add(new LoopBinder(video));

            //PropertyItemsControl.ItemsSource = propsToDisplay;

            FormGrid.SelectedObject = video;
            //Show();
        }

      
        private void ConfigureActionButton_Click(object sender, RoutedEventArgs e) {
            ActionBinder binder = (ActionBinder)(((Button)sender).Tag);
            
            //Configure this Action
            CoreConfig currentConfig = Globals.ThisAddIn.GetCurrentConfig();
            PageChooserControl pageChooser = new PageChooserControl(currentConfig);
            HostForm newDialog = new HostForm(pageChooser);
            if(newDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                if(binder.Value.Action == null) {
                    binder.Value.Action = new NavigationAction();
                }
                PageConfig selectedPage = pageChooser.SelectedPage;
                binder.Value.Action.Section = selectedPage.ParentSlideConfig.SlideId;
                binder.Value.Action.Page = selectedPage.PageId;
                binder.Value.Action.Jump = true;
            }
        }

    }
}
